﻿using UnityEngine;
using System.Collections;
using FM_Mono;

[IgnoreGen]
public class UVAnimation : MonoBehaviour
{
	private static MaterialPropertyBlock mpb = null;
	private static int nameId = -1;

	public float x1speed = 0;
	public float y1speed = 0;

	public float tilingX = 1;

	public float tilingY = 1;


	private Vector4 v1;

	private Renderer _renderer;

	void Start()
	{
		v1 = new Vector4 (tilingX, tilingY, 0, 0);
		_renderer = GetComponent<Renderer> ();

		if (mpb == null)
		{
			nameId = Shader.PropertyToID ("_MainTex_ST");
			mpb = new MaterialPropertyBlock ();
		}
		//AssetBundleManager.GetBundle("dataconfig", getdata);
	}
	void Update()
	{	
#if UNITY_EDITOR
		v1.x = tilingX;
		v1.y = tilingY;
#endif
		float deltaTime = Mathf.Clamp(Time.smoothDeltaTime, 0, 0.0333f);
		
		v1.z += deltaTime*x1speed;
		v1.z -= (int) v1.z;
		v1.w += deltaTime*y1speed;
		v1.w -= (int) v1.w;
		_renderer.GetPropertyBlock (mpb);
		mpb.SetVector (nameId, v1);
		_renderer.SetPropertyBlock (mpb);
		//	GetComponent<Renderer>().materials[0].mainTextureOffset = v1;
	}


}
